package com.ccys.cms.controller.administrator;

import com.ccys.cms.service.administrator.TblI18nWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.administrator.TblI18nDTO;
import com.ccys.db.entity.TblI18n;
import com.ccys.db.vo.administrator.TblI18nWebVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "系统设置-i18n")
@RequestMapping("administrator")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) // 开启跨域访问允许
@SuppressWarnings("unchecked")
public class I18nWebController {

    @Autowired
    private TblI18nWebService tblI18nWebService;

    @GetMapping("i18n")
    @ApiOperation("获取列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "对象id", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "objTable", value = "对象表与页面单词对应(tbl_introduction,tbl_content,tbl_medication_usage_period,tbl_symptom,tbl_medication_reaction,tbl_specialist_company(特殊对应前端的Panel management页面),tbl_faq,tbl_faq_type,tbl_unit_of_measurement,tbl_diagnosis,tbl_formulation_quantity_type）", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblI18nWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblI18nDTO dto) {
        return this.tblI18nWebService.listObjectsCms(request, response, dto);
    }


    @PostMapping("i18n")
    @ApiOperation("添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "languageId", value = "languageId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "language", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "objId", value = "objId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "objTable", value = "对象表与页面单词对应(tbl_introduction,tbl_content,tbl_medication_usage_period,tbl_symptom,tbl_medication_reaction,tbl_specialist_company(特殊对应前端的Panel management页面),tbl_faq,tbl_faq_type,tbl_unit_of_measurement,tbl_diagnosis,tbl_formulation_quantity_type）", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "content", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblI18n entity) {
        entity.setId(null);
        return this.tblI18nWebService.change(request, response, entity);
    }


    @PutMapping("i18n")
    @ApiOperation("编辑")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "languageId", value = "languageId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "language", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "objId", value = "objId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "objTable", value = "对象表与页面单词对应(tbl_introduction,tbl_content,tbl_medication_usage_period,tbl_symptom,tbl_medication_reaction,tbl_specialist_company(特殊对应前端的Panel management页面),tbl_faq,tbl_faq_type,tbl_unit_of_measurement,tbl_diagnosis,tbl_formulation_quantity_type）", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "content", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblI18n entity) {
        Kit.allParamValid(entity, "id");
        return this.tblI18nWebService.change(request, response, entity);
    }


    @DeleteMapping("i18n")
    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult delete(HttpServletRequest request, HttpServletResponse response, TblI18n dto) {
        return this.tblI18nWebService.delete(request, response, dto);
    }

}